package com.zxj.geekstudy.spring;

import com.zxj.geekstudy.spring.Apple;
import com.zxj.geekstudy.spring.Banana;
import com.zxj.geekstudy.spring.FruitConfig;
import com.zxj.geekstudy.spring.aop1.Food;
import com.zxj.geekstudy.spring.aop1.Peach;
import com.zxj.geekstudy.spring.aop2.Strawberry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 2.（必做）写代码实现 Spring Bean 的装配，方式越多越好（XML、Annotation 都可以）, 提交到 GitHub。
 */
public class TestSpringApplication {

	public static void main(String[] args) {

		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

		Apple apple = (Apple) applicationContext.getBean("apple");
		System.out.println(apple);
		Banana banana = (Banana) applicationContext.getBean("banana");
		System.out.println(banana);
		FruitConfig fruitConfig = (FruitConfig) applicationContext.getBean("fruitConfig");
		System.out.println(fruitConfig);
		Food fruit = applicationContext.getBean(Food.class);
		System.out.println(fruit.getClass());
		fruit.testAop();
		Peach peach = applicationContext.getBean(Peach.class);
		System.out.println(peach.getClass());
		peach.testAop();

		Strawberry strawberry = applicationContext.getBean(Strawberry.class);
		System.out.println(strawberry.getClass());
		strawberry.testAop();

		Banana banana101 = (Banana) applicationContext.getBean("banana101");
		System.out.println(banana101);
		Banana banana102 = (Banana) applicationContext.getBean("banana102");
		System.out.println(banana102);
	}

}
